package com.xiaoxi.singletonmode.singleton;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Ticket
 * @Description
 * @Author xiaoxi
 * @Date 2023/3/12 14:39
 * @Version 1.0
 */
public class Ticket {

    private static Ticket[] tickets = new Ticket[]{
            new Ticket(0),
            new Ticket(1),
            new Ticket(2)
    };
    private int ticketNum = 100;

    private Ticket(int id) {
        System.out.println("生成了一个实例，编号：" + id);
    }

    public static Ticket getInstance(int id) {
        if (id >= 3) {
            return null;
        }
        return tickets[id];
    }

    public void cellTicket() {
        System.out.println("购票成功");
        ticketNum--;
        System.out.println("还剩：" + ticketNum + "张");
    }

}
